package avicit.bdp.dcs.json.service.reader;

import avicit.bdp.dcs.datasource.dto.JobDatasource;
import avicit.bdp.dcs.datasource.service.DataSourceUtils;
import avicit.bdp.dcs.job.dto.JobDTO;
import avicit.bdp.dcs.plugin.BaseDataxParam;
import avicit.bdp.dcs.task.dto.TaskDTO;
import avicit.bdp.dcs.utils.JdbcConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class StructureReaderBuilder {

  @Autowired private RdbmsReaderBuilder rdbmsReaderBuilder;
  @Autowired private OdpsReaderBuilder odpsReaderBuilder;
  @Autowired private DataSourceUtils dataSourceUtils;

  /** 构建应用数据采集Reader */
  public BaseDataxParam buildReaderByStructure(TaskDTO taskDTO, JobDTO jobDTO)
          throws Exception {
    JobDatasource readerDatasource = dataSourceUtils.convertDatasource(jobDTO.getSrcDatasourceId());

    if (JdbcConstants.ODPS.equals(readerDatasource.getDbType())) {
      return odpsReaderBuilder.buildOdpsReaderByStructure(taskDTO, jobDTO);
    } else {
      return rdbmsReaderBuilder.buildRdbmsReaderByStructure(taskDTO, jobDTO);
    }
  }

}
